import store from '../../store';
import {hideLoading, showLoading} from '../../store/actions';
import React, {Component} from "react";
import {Icon} from "antd";
import './loading.less';
import {connect} from 'react-redux';

class Loading extends Component {
  render () {
    let {spin} = this.props || {};

    let className = "loading-mask";
    if (spin && spin.spinning) {
      className = 'loading-mask show';
    }

    return (
      <div className={className}>
        <Icon type="loading"/>
      </div>
    );
  }

  static show () {
    store.dispatch(showLoading())
  }

  static hide () {
    store.dispatch(hideLoading())
  }
}

export default connect((state, ownProps) => {
  return {
    spin: state.spin
  }
})(Loading);